<?php
// Chức năng login vào hệ thống
session_start();
include "../util/dataUtil.php";
$userlogin = $_POST["idnhanvien"];
$pass = $_POST["pass"];



$sql = "select * from nhanvien where id_Nhanvien='$userlogin' and MatKhau='$pass' ";
//echo $sql;
// lay thong tin chi tiet cua nhan vien
$sql2 = "select HoTen from chitietnhanvien where id_NhanVien = '$userlogin'";
$ketqua = executeQuery($sql2);
while ($tennv = mysql_fetch_array($ketqua)){
    $_SESSION["tennhanvien"] = $tennv["HoTen"];   } 

$listuser = executeQuery($sql);

$count=0;


while ($row = mysql_fetch_array($listuser)){
    //login thanh cong
   
    $_SESSION["userlogin"] = $row["id_Nhanvien"];
    $_SESSION["vaitro"] = $row["MaVaiTro"];
    $count++;

    if($_SESSION["vaitro"]==1){
        $_SESSION["vaitro"]="Quản Trị";
        header("location:../admin/dean.php");
    }else{
        $idvaitro = $_SESSION["vaitro"];
        $sqlvaitro = "select TenVaiTro from vaitro where id= $idvaitro";
        $kqvaitro = executeQuery($sqlvaitro);
        while($tenvaitro = mysql_fetch_array($kqvaitro)){
            $_SESSION["vaitro"]=$tenvaitro["TenVaiTro"];
        }
        
        header("location:../view/dsdeanthamgia.php");
    }
}

if($count==0){
    //login that bai
    $_SESSION["thongbao"]=" Đăng nhập không thành công! ";
    header("location: ../index.php");
}




?>